home *** CD-ROM | disk | FTP | other *** search
Text File | 1993-12-17 | 19.2 KB | 557 lines | [TEXT/MPS ] |
- #
- # ****************************************************************************
- #
- # File Name: Palette.Lib
- #
- # Contains: xxx put contents here xxx
- #
- # Written by: Kevin Avoy, Ken Landreth, Michael Leong, Gil Spencer et al
- #
- # Copyright: © 1993 by Apple Computer, Inc., all rights reserved.
- #
- # ****************************************************************************
- # C h a n g e H i s t o r y (most recent first):
- # ****************************************************************************
- #
- # Vers Date Author Description
- # ---- -------- ------ ---------------------------------------------
- # <1.0.6+> 11/19/93 NAGA modify TCS format
- # <1.0.6> 8/25/93 KTA Added support for parity checking the TCS stack.
- # <1.0.5> 8/3/93 KTA SelFromCoord() - There was no returnVal for absolute coordinate
- # moves.
- # <1.0.4> 6/8/93 NAGA unmark tasks that are not published
- # <1.0.3> 5/21/93 NAGA Adding header and porting old files to follow new standards
- #
- # ****************************************************************************
- #
-
- ########################################################################
- # External libraries
- #=======================================================================
- Libraries "TCS.Lib","Output.Lib","UserInterface.Lib";
-
- #########################################################################
- #########################################################################
- # Palette Structure Accessors()
- #========================================================================
- # Author: DM (x41220)
- # Description: These functions access the data in an palette data struct
- # Parameters: palStruct
- # Returns: the requested data element or list
- #========================================================================
- # History:
- #
- #########################################################################
- task GetPalRect(palStruct) begin return( palStruct[1] ); end;
- task GetPalType(palStruct) begin return( palStruct[2] ); end;
- task GetPalMatrixSize(palStruct) begin return( palStruct[3] ); end;
- task GetPalOffsets(palStruct) begin return( palStruct[4] ); end;
- #task GetPalHeaderSize(palStruct) begin return( palStruct[5] ); end; # Not used
- #task GetPalOnDesk(palStruct) begin return( palStruct[6] ); end; # Not used
-
- task InsertPalRect(rect, pS) begin return( replace(rect, 1, pS )); end;
- task InsertPalOnDesk(onDesk, pS) begin return( replace(onDesk, 6, pS ));end;
-
-
- #########################################################################
- # Tool Structure Accessors()
- #========================================================================
- # Author: DM (x41220)
- # Description: These functions access the data in an tool data struct
- # Parameters: elemStruct
- # Returns: the requested data element or list
- #========================================================================
- # History:
- #
- #########################################################################
- ## elemStruct is the data structure that completely specifies tools
- ## elemStruct {
- ## ElemNum
- ## PalNum
- ## ElemName
- ## ElemType - kClick := move-click
- ## (Pointlist is single set of points)
- ## - kDrag := move-pressmouse-move-releasMouse
- ## (Pointlist is two set of points)
- ## == Pointlist is defined by Global gNumPoints ==
- ## - kMultiDrag := move-pressmouse-move-move…releasMouse
- ## - kMultiClick:= move-click-move-click-move…
- ## - kMultiClickDragTool := move-pressmouse-move-releasMouse-pressmouse-move-releasMouse…
- ##
- ## elemDblClk - Flag to doulble click when finished
- ## - 0 := No DoubleClick
- ## - 1 := DoubleClick
- ##
- ## SetAttribute - Flag indicating when to set attributes
- ## - 0 := No attributes to set
- ## - 1 := Set attribute before drawing object
- ## - 2 := Set attribute after drawing object
- ## - "str" := Type <'Str'> after drawing object (texttool)
- ## }
- ## Defined ElemTypes:
- ##
- #########################################################################
- ## Example: global CharTool := { ElemNum, PalNum,"ElemName", ElemType, elemDblClk};
- ## global CharTool := { 17 , 1 ,"Char" , kClick , 0 };
- #########################################################################
- task GetElemNum(elemStruct) begin return( elemStruct[1] ); end;
- task GetPalNum(elemStruct) begin return( elemStruct[2] ); end;
- task GetElemName(elemStruct) begin return( elemStruct[3] ); end;
- task GetElemType(elemStruct) begin return( elemStruct[4] ); end;
- task GetElemDblClk(elemStruct) begin return( elemStruct[5] ); end;
-
- task GetAttributes(elemStruct) begin return( elemStruct[6] ); end;
- task GetSetAttribute(elemStruct) begin return( elemStruct[6][1] ); end;
- task GetPatternFlag(elemStruct) begin return( elemStruct[6][2] ); end;
- task GetLineFlag(elemStruct) begin return( elemStruct[6][3] ); end;
- task GetColorFlag(elemStruct) begin return( elemStruct[6][4] ); end;
-
- task InsertElemNum(eNum, tS) begin return( replace( eNum, 1, tS )); end;
- task InsertPalNum(pNum, tS) begin return( replace( pNum, 2, tS )); end;
- task InsertElemName(eNam, tS) begin return( replace( eNam, 3, tS )); end;
- task InsertElemType(eTyp, tS) begin return( replace( eTyp, 4, tS )); end;
- task InsertElemDblClk(eDbc, tS) begin return( replace( eDbc, 5, tS )); end;
- task InsertSetAttribute(eDbc, tS) begin return( replace( eDbc, 6, tS )); end;
-
- #########################################################################
- # PalettePicker(elemStruct)
- #========================================================================
- # Author: DM
- # Description: Dispatches selection request to palette handlers.
- # Parameters: elemStruct:= Structure containing element info
- # Only the first 3 elements are required.
- # kInWindPal := 1;
- # kIsWindPal := 2;
- # kPullOffPal:= 3;
- # kPopUpPal := 4;
- # kScrollPal := 5;
- #
- # Return Values: 1 - OK
- # 0 - error
- # Examples: PalettePicker(elemStruct);
- #========================================================================
- # History:
- # KTA 8/24/93 TCS stack parity check
- #########################################################################
- TASK PalettePicker(elemStruct := {}, ObjectNumber := 0) begin
- if (global gDebugFlag)
- Println "----- PalettePicker() - Palette.lib --------";
- global kPalDocWind, kPalWind, kPullOffPal, kPopUpPal, kScrollPal, kDebugLog;
- global gPaletteList;
-
- thePalNum := GetPalNum(elemStruct); # get the palette number
- #### Handle Direct Coordinate Tools #####
- if (TypeOF(thePalNum) = 'list')
- begin
- returnVal := SelFromCoord(elemStruct,ObjectNumber); # no palette only coordinates
- if (returnVal)
- returnVal := elemStruct;
- end;
- else
- begin
- theElemName := GetElemName(elemStruct); # get the elem name
- theElemNum := GetElemNum(elemStruct); # get the elem number
- thePalette := gPaletteList[thePalNum]; # get the palette
- thePalType := GetPalType(thePalette); # get the palette type
- theElemNum := "{theElemNum}"; # Num to String
- myPal := "{thePalNum}";
- if(Card(theElemNum) = 1) # if its a single digit add a zero
- theElemNum := "0" + theElemNum;
- TCSNum := "{myPal}" + "{theElemNum}";
- TCSNum := StrToNum( TCSNum );
- TCSStart({ TCSNum, global kTCSetPalettePicker },"PalettePicker"); # Start TCS
-
- LogStr("Preparing to select the '{theElemName}' tool / number - '{theElemNum}' from Palette #{thePalNum}",4);
- if (thePalType = kPalDocWind)
- returnVal := SelFromDocWind(elemStruct);
- else if (thePalType = kPalWind)
- returnVal := SelFromPalWind(elemStruct);
- else if (thePalType = kPullOffPal)
- returnVal := SelFromPullOff(elemStruct);
- else if (thePalType = kPopUpPal) begin
- returnVal := SelFromPopUp(elemStruct);
- end;
- else if (thePalType = kScrollPal)
- returnVal := SelFromScroll(elemStruct);
- else begin
- LogStr("No selection function declared for palette type {thePalType}",2);
- returnVal := 0;
- end;
- TCSEnd({ TCSNum, global kTCSetPalettePicker }, returnVal,,ObjectNumber,theElemName);
- end;
- return(returnVal); #Return what sub routines return
- end;
-
-
- #########################################################################
- # CalcOffset(elemStruct)
- #========================================================================
- # Author: KTA
- # Description: Calculates tool offsets based on palette info.
- # Parameters: elemStruct:= structure containing element info
- # Return Values: toolOffset:= {x,y}
- # 0 - error
- # Examples: CalcOffset(elemStruct);
- #========================================================================
- # History:
- #
- #########################################################################
- task CalcOffset(elemStruct)
- begin
- global gPaletteList, kPopUpPal, kDebugLog;
-
- #LogStr("Calculating tool offset");
- thePalNum := GetPalNum(elemStruct);
- thePalette := gPaletteList[thePalNum];
- thePalType := GetPalType(thePalette);
- elemNum := GetElemNum(elemStruct);
- theRect := GetPalRect(thePalette);
- theOffsets := GetPalOffsets(thePalette);
- theMatrix := GetPalMatrixSize(thePalette);
- headerHeight := 0;
-
- xOffset := theOffsets[1];
- yOffset := theOffsets[2];
- elemsAcross := theMatrix[1];
- elemsDown := theMatrix[2];
-
- if ((Card(theRect) = 1) or (Card(theRect) = 2)) # kPalWind
- begin # be a seperate palette window
- if (theRect[2])
- headerHeight := theRect[2];
-
- theWindow := Findwindow(theRect[1]);
- if (TheWindow)
- theRect := TheWindow.r;
- end;
-
- if ((elemNum <= elemsAcross) and (elemsAcross > 1))
- begin
- xMove := elemNum * xOffset;
- #Println "xMove1 - ", xmove;
- end;
- else
- begin
- if ((elemNum mod elemsAcross) <> 0)
- begin
- xMove := ((elemNum mod elemsAcross)) * xOffset;
- #Println "xMove2 - ", xmove;
- end;
- else
- begin
- if (elemsAcross = 1) # Fix to handle palettes with only 1 column of tools
- begin
- xMove := (theRect[1]+theRect[3])/2;
- #Println "xMove3 - ", xmove;
- end;
- else
- begin
- xMove := ((elemsAcross)) * xOffset;
- #Println "xMove4 - ", xmove;
- end;
- end;
- end;
- if (elemNum mod elemsAcross = 0) and (yOffset <> 0)
- begin
- yMove := (elemNum/elemsAcross) * yOffset;
- #Println "yMove1 - ", ymove;
- end;
- else
- begin
- if (elemsDown = 1) # Fix to handle palettes with only 1 row of tools
- begin
- yMove := (theRect[2]+theRect[4])/2 - (theRect[2] + headerHeight);
- #Println "yMove2 - ", ymove;
- end;
- else
- begin
- yMove := (elemNum/elemsAcross +1) * yOffset;
- #Println "yMove3 - ", ymove;
- end;
- end;
- xAbsoluteOffSet := theRect[1];
- yAbsoluteOffSet := theRect[2] + headerHeight;
-
- if (thePalType = kPopUpPal) #To handle popup palettes when selecting from a
- begin # palette you begin at the correct location.
- xAbsoluteOffSet := 0;
- yAbsoluteOffSet := 0;
- end;
- if (elemsAcross = 1)
- xAbsoluteOffSet := 0;
-
- xMove := xMove + xAbsoluteOffSet - xOffset/2;
- yMove := yMove + yAbsoluteOffSet - yOffset/2;
- If((xMove) or (yMove))
- returnVal := {xMove, yMove};
- else
- returnVal := 0;
- #Println "This is the CalcOffset returnVal - ", returnVal;
- return(returnVal);
- end; # CalcOffset()
-
- #########################################################################
- # SelFromDocWind(elemStruct)
- #========================================================================
- # Author: DM
- # Description: Selects tools from palettes that are builtin to doc windows.
- # You can also specify a Rect in Global coordinates outside
- # the document window.
- # Parameters: elemStruct
- # Return Values: 1 - OK
- # 0 - error
- # Examples: SelFromDocWind(elemStruct);
- #========================================================================
- # History:
- #
- #########################################################################
- TASK SelFromDocWind(elemStruct)
- begin
- global gPaletteList;
- windSpecifier := 0;
- thePalNum := GetPalNum(elemStruct);
- thePalette := gPaletteList[thePalNum];
- theRect := GetPalRect(thePalette);
-
- LogStr("Selecting from a palette that in a doc window");
-
- whereMove := CalcOffset(elemStruct);
- if(whereMove)
- begin
- xMove := whereMove[1];
- yMove := whereMove[2];
- temp := global gDisableAllLogging;
- if not(global gDebugFlag)
- gDisableAllLogging := 1;
- if (Card(theRect) = 4)
- MoveMouse(xMove, yMove, 1, 2); # Select Tool/Absolute Coordinates
- else if(Card(theRect) = 5)
- begin
- windSpecifier := theRect[5];
- MoveRelativeToWindow(xMove, yMove, windSpecifier, 2); # Select Tool/Relative to doc window
- end;
- gDisableAllLogging := temp;
- returnVal := 1;
- end;
- else
- returnVal := 0;
-
- return(returnVal);
- end;
- #########################################################################
- # SelFromPalWind(elemStruct)
- #========================================================================
- # Author: DM
- # Description: Selects tools from palettes that are windows.
- # Parameters: elemStruct:= structure containing element info
- # Return Values: 1 - OK
- # 0 - error
- # Examples: SelFromPalWind(elemStruct);
- #========================================================================
- # History:
- #
- #########################################################################
- TASK SelFromPalWind(elemStruct)
- begin
- LogStr("Selecting from a palette that is in a separate window");
- returnVal := 0;
-
- whereMove := CalcOffset(elemStruct);
- if(whereMove)
- begin
- xMove := whereMove[1];
- yMove := whereMove[2];
- temp := global gDisableAllLogging;
- if not(global gDebugFlag)
- gDisableAllLogging := 1;
- MoveMouse(xMove, yMove, , 2); # Select tool
- gDisableAllLogging := temp;
- returnVal := 1;
- end;
- else
- returnVal := 0;
-
- return(returnVal);
- end;
- #########################################################################
- # SelFromPullOff(elemStruct)
- #========================================================================
- # Author: DM
- # Description: Selects tools from palettes that tear off menu bar.
- # Parameters: elemStruct:= structure containing tool info
- # Return Values: 1 - OK
- # 0 - error
- # Examples: SelFromPullOff(elemStruct);
- #========================================================================
- # History:
- #
- #########################################################################
- TASK SelFromPullOff(elemStruct)
- begin
- if (global gDebugFlag)
- Println "----- SelFromPullOff() - Palette.lib --------";
- LogStr("Selecting from a palette that pulls off");
-
- end;
- #########################################################################
- # SelFromCoord(elemStruct, ObjectNumber)
- #========================================================================
- # Author: KTA
- # Description: Selects tools from coodinates either global or relative to the
- # front window.
- # Parameters: elemStruct:= structure containing tool info
- # Return Values: Returns what is returned by MoveRelativeToWindow() or MoveMouse()
- # Examples: SelFromCoord(elemStruct);
- #========================================================================
- # History:
- # KTA 8/3/93 There was no returnVal for absolute coordinate moves.
- # KTA 8/24/93 TCS stack parity check
- #########################################################################
- TASK SelFromCoord(elemStruct,ObjectNumber)
- begin
- temp := global gDisableAllLogging;
- if not(global gDebugFlag)
- gDisableAllLogging := 1;
-
- theElemName := GetElemName(elemStruct); # get the elem name
- theCoord := GetPalNum(elemStruct); # get the palette number
- theElemNum := GetElemNum(elemStruct); # get the elem number
- xCoor := theCoord[1];
- yCoor := theCoord[2];
- RelativeFlag := theCoord[3];
-
-
- TCSNum := theElemNum;
- TCSStart({ TCSNum, global kTCSetToolPalette },"SelectFromCoord"); # Start TCS
-
- Str := "Selecting the '{theElemName}' tool from coordinates ∂({xCoor},{yCoor}∂)";
- if (RelativeFlag) # RelativeToWindow
- begin
- returnVal := MoveRelativeToWindow(xCoor, yCoor, ,2,,RelativeFlag);
- str1:= " which are relative to the front window";
- end;
- else # Absolute Coordinates
- begin
- MoveMouse(xCoor, yCoor, , 2);
- returnVal:= 1;
- str1:= " which are absolute coordinates";
- end;
- # Tool has been Selected
-
- Str := Str + str1;
- gDisableAllLogging := temp;
- LogStr(Str);
- if (returnVal)
- TCSReturn :=1;
- else
- TCSReturn :=0;
- TCSEnd({ TCSNum, global kTCSetToolPalette }, TCSReturn,,ObjectNumber,theElemName);
-
- return(returnVal);
- end;
- #########################################################################
- # SelFromPopUp(elemStruct)
- #========================================================================
- # Author: DM
- # Description: Selects tools from palettes that pop up.
- # Parameters: elemStruct:= structure containing element info
- # Return Values: 1 - OK
- # 0 - error
- # Examples: SelFromPopUp(elemStruct);
- #========================================================================
- # History:
- #
- #########################################################################
- TASK SelFromPopUp(elemStruct)
- begin
- windSpecifier := 0;
- global gPaletteList, kDebugLog, gAppVerify;
- thePalNum := GetPalNum(elemStruct);
- thePalette := gPaletteList[thePalNum];
- theRect := GetPalRect(thePalette);
- if (global gDebugFlag)
- println "This is the ElemStruct", elemStruct;
- # if we are moving with absolute coordinates the rect should have 4 items
- if (Card(theRect) = 4)
- AbsoluteCoord := 1;
- else if (Card(theRect) = 5) # IF
- windSpecifier := theRect[5];
-
- whereMove := CalcOffset(elemStruct);
- if(whereMove)
- begin
- xMove := whereMove[1];
- yMove := whereMove[2];
- returnVal := 1;
- end;
- else
- returnVal := 0;
-
- tempSpeed := MouseSpeed(5);
- temp := global gDisableAllLogging;
- if not(global gDebugFlag)
- gDisableAllLogging := 1;
-
- if (AbsoluteCoord)
- MoveMouse(theRect[1], theRect[2], 1, 0); # move to pop-point
- else
- MoveRelativeToWindow(theRect[1], theRect[2], windSpecifier, 0); # move to pop-point
-
- tempAppVerify := gAppVerify;
- gAppVerify := 0;
- PressMouse;
- wait(2);
- MoveMouse(theRect[3] - theRect[1], theRect[4] - theRect[2], 0, 0); # press mouse - move to topLeft item
- MoveMouse(xMove, yMove, 0, 0); # move to item and release
- ReleaseMouse;
- gAppVerify := tempAppVerify;
- gDisableAllLogging := temp;
- MouseSpeed(tempSpeed);
-
- return(returnVal);
- end;
- #########################################################################
- # SelFromScroll(elemStruct)
- #========================================================================
- # Author: DM
- # Description: Selects elements from palettes that are builtin to doc windows.
- # Parameters: elemStruct:= structure containing element info
- # Return Values: 1 - OK
- # 0 - error
- # Examples: SelFromScroll(elemStruct);
- #========================================================================
- # History:
- #
- #########################################################################
- TASK SelFromScroll(elemStruct)
- begin
- if (global gDebugFlag)
- Println "----- SelFromScroll() - Palette.lib --------";
- LogStr("Selecting from a palette that scrolls");
-
- end;
-
- #########################################################################
- # GetRandomElement()
- #========================================================================
- # Author: DM (x41220)
- # Description:
- # Parameters: palStruct
- # Returns:
- #========================================================================
- # History:
- #
- #########################################################################
- TASK GetRandomElement(palStruct) begin
- if (global gDebugFlag)
- Println "----- GetRandomElement() - Palette.lib --------";
- global kDebugLog;
- theMatrix := GetPalMatrixSize(palStruct);
- numCells := theMatrix[1]*theMatrix[2];
-
- elemNum := random(1, numCells);
- return elemNum;
- end; # GetRandomElement()
-
-
-